/*
 * @Author: codeD
 * @Date: 2022-02-17 20:45:33
 * @LastEditors: codeD
 * @LastEditTime: 2022-02-17 22:14:56
 * @Description: file content
 * @FilePath: \wpt\src\components\Search\effect.tsx
 */
import React ,{useEffect,ChangeEvent,MouseEvent,useState}from 'react'
import {SearchProps} from './type'
const useEffectSearch=(props:SearchProps)=>{
    const {placeholder,defaultValue,onSearch,value}=props

const [currentValue,setCurrentValue]=useState('');
const handleChange=(e:ChangeEvent<HTMLInputElement>)=>{
     const aValue=e.target.value;
     setCurrentValue(aValue)
   
}

const handleCancelIconClick=()=>{
    setCurrentValue('')
}
const values=(value!==undefined)?value:currentValue
return{
    values,
    placeholder,
    handleChange,
    handleCancelIconClick
}
}
export default useEffectSearch